<?php
declare (strict_types=1);

namespace app\dao\log;

use app\dao\BaseDao;
use app\model\log\UserLoginLog;
use think\db\exception\DbException;

/**
 *
 * Class UserLoginLogDao
 * @package app\dao\log
 * @mixin UserLoginLog
 */
class UserLoginLogDao extends BaseDao
{

    /**
     * 设置模型
     * @return string
     */
    protected function setModel(): string
    {
        return UserLoginLog::class;
    }


    /**
     * 登录日志
     * @param array $whereData
     * @param int $page
     * @param int $limit
     * @param array $with
     * @return array
     * @throws DbException
     */
    public function getLogList(array $whereData, int $page, int $limit, array $with = ['user']): array
    {
        return UserLoginLog::with($with)
            ->withSearch(array_keys($whereData), $whereData)
            ->order('id desc')
            ->paginate([
                'list_rows' => $limit,
                'var_page' => 'page'
            ])->each(function ($item, $key) {
                return $item;
            })
            ->toArray();
    }
}
